<?php
include("_mysql.php");
include("_settings.php");
include("_functions.php");

$json_result = array();

if (isset($_POST["id"])) {
	$id = $_POST["id"];	
	$result = safe_query("SELECT * FROM news WHERE newsID = " . $id . " ORDER BY DATE DESC LIMIT 1");
	if ($result) {
		$result_count = safe_query("SELECT COUNT(*) AS count FROM comments WHERE newsID = " . $id);
		$data_count = mysql_fetch_assoc($result_count);
		$count_comment = $data_count["count"];
		
		$news = mysql_fetch_assoc($result);
		$json_result["title"] = $news["title"];
		$json_result["description"] = $news["description"];
		$json_result["content"] = $news["content"];
		$json_result["date"] = date("F j, Y", $news["date"]);
		$json_result["pic"] = $news["pic"];
		$json_result["comments"] = $count_comment .  " Commments";
		
		
	} 
}

echo json_encode($json_result);
?>